using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Material.Object;
using Material.DAL;
namespace Material.Entity
{
	public class TblTransHutangDTLEntity
	{
		private Accessor accessor;
		private string connString;

		public TblTransHutangDTLEntity (string _connString)
		{
			 this.connString = _connString;
		}

		public int Insert(TblTransHutangDTL tbltranshutangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangDTL_Insert";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add("@IdTransDTL" ,tbltranshutangdtl.IdTransDTL );
			 accessor.Add("@IdTransHDR" ,tbltranshutangdtl.IdTransHDR );
			 accessor.Add("@TglBayar" ,tbltranshutangdtl.TglBayar );
			 accessor.Add("@JumlahBayar" ,tbltranshutangdtl.JumlahBayar );
			 accessor.Add("@CreatedDate" ,tbltranshutangdtl.CreatedDate );
			 accessor.Add("@CreatedBy" ,tbltranshutangdtl.CreatedBy );
			 accessor.Add("@ModifiedDate" ,tbltranshutangdtl.ModifiedDate );
			 accessor.Add("@ModifiedBy" ,tbltranshutangdtl.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Update(TblTransHutangDTL tbltranshutangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangDTL_Update";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranshutangdtl.IdTransDTL );
			 accessor.Add(@"IdTransHDR" ,tbltranshutangdtl.IdTransHDR );
			 accessor.Add(@"TglBayar" ,tbltranshutangdtl.TglBayar );
			 accessor.Add(@"JumlahBayar" ,tbltranshutangdtl.JumlahBayar );
			 accessor.Add(@"CreatedDate" ,tbltranshutangdtl.CreatedDate );
			 accessor.Add(@"CreatedBy" ,tbltranshutangdtl.CreatedBy );
			 accessor.Add(@"ModifiedDate" ,tbltranshutangdtl.ModifiedDate );
			 accessor.Add(@"ModifiedBy" ,tbltranshutangdtl.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Delete(TblTransHutangDTL tbltranshutangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangDTL_Delete";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranshutangdtl.IdTransDTL);

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public TblTransHutangDTL GetDataByID(TblTransHutangDTL tbltranshutangdtl)
		{
			 TblTransHutangDTL result = new TblTransHutangDTL();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangDTL_SelectByID";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranshutangdtl.IdTransDTL);

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 result.IdTransDTL = rdr.GetInt32(0);
						 result.IdTransHDR = rdr.GetInt32(1);
						 result.TglBayar = rdr.GetDateTime(2);
						 result.JumlahBayar = rdr.GetDecimal(3);
						 result.CreatedDate = rdr.GetDateTime(4);
						 result.CreatedBy = rdr.GetString(5);
						 result.ModifiedDate = rdr.GetDateTime(6);
						 result.ModifiedBy = rdr.GetString(7);
					  }
			}
			 return result;
		}

		public List<TblTransHutangDTL> GetDataAll()
		{
			 List<TblTransHutangDTL> result = new List<TblTransHutangDTL>();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangDTL_SelectAll";
			 accessor.CommandType = CommandType.StoredProcedure;

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 TblTransHutangDTL obj = new TblTransHutangDTL();
						 obj.IdTransDTL = rdr.GetInt32(0);
						 obj.IdTransHDR = rdr.GetInt32(1);
						 obj.TglBayar = rdr.GetDateTime(2);
						 obj.JumlahBayar = rdr.GetDecimal(3);
						 obj.CreatedDate = rdr.GetDateTime(4);
						 obj.CreatedBy = rdr.GetString(5);
						 obj.ModifiedDate = rdr.GetDateTime(6);
						 obj.ModifiedBy = rdr.GetString(7);
						 result.Add(obj);
					  }
			}
			 return result;
		}

	}
}
